﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Transactions;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using _4T.Data;
using _4T.DAL;

namespace _4T.BLL
{
    public class ProfileBLL
    {
        public ProfileBLL() { }

        public bool InsertProfileInfo(Profile profile, string currentUser)
        {
            bool result = false;
            int patientID = 0;
            int medicalID = 0;
            int infoSupplierID = 0;
            if (profile != null)
            {
                try
                {
                    ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings["cnnString4T"];
                    if (ConnectionStringSettings != null && !string.IsNullOrEmpty(ConnectionStringSettings.ConnectionString.Trim()))
                    {
                        using (TransactionScope transScope = new TransactionScope())
                        {
                            using (SqlConnection connection = new SqlConnection(ConnectionStringSettings.ConnectionString))
                            {
                                string profileCode = string.Empty;
                                if (profile.ProfileInfo != null && string.IsNullOrEmpty(profile.ProfileInfo.ProfileInfoCode))
                                {
                                    ProfileDAL profileDAL = new ProfileDAL();
                                    profileCode = profileDAL.InsertNewProfile(null);
                                }
                                else
                                {
                                    profileCode = profile.ProfileInfo.ProfileInfoCode;
                                }

                                if (!string.IsNullOrEmpty(profileCode))
                                {
                                    if (profile.PatientInfo != null)
                                    {
                                        PatientInfo patient = profile.PatientInfo;
                                        PatientInfoDAL patientDAL = new PatientInfoDAL();
                                        patientID = patientDAL.InsertPatientInfo(patient.PatientName, patient.Birthday, patient.Gender, patient.IDNumber, patient.PermanentAddress, patient.TemporaryAddress, patient.MobileNumber, patient.PhoneNumber, patient.EmergencyRepresentative, patient.RepresentativePhoneNumber, patient.LocalContactPoint, patient.LocalContactPointPhoneNumber, patient.LocalMedicalStaff, patient.LocalMedicalStaffPhoneNumber, patient.MedicalFacility, patient.Note);
                                    }
                                    if (profile.MedicalInfo != null)
                                    {
                                        MedicalInfo medical = profile.MedicalInfo;
                                        MedicalInfoDAL medicalDAL = new MedicalInfoDAL();
                                        medicalID = medicalDAL.InsertMedicalInfo(medical.Diagnosis, medical.MedicalTime, medical.TreatmentMethod, medical.Situation, medical.Support, medical.Note);
                                    }
                                    if (profile.InfoSupplierInfo != null)
                                    {
                                        InfoSupplierInfo supplier = profile.InfoSupplierInfo;
                                        InfoSupplierInfoDAL supplierDAL = new InfoSupplierInfoDAL();
                                        infoSupplierID = supplierDAL.InsertInfoSupplierInfo(supplier.SupplierName, supplier.PhoneNumber, supplier.PersonalCode, supplier.Email, supplier.Note);
                                    }

                                    if (patientID > 0 && medicalID > 0 && infoSupplierID > 0 && profile.ProfileInfo != null)
                                    {
                                        ProfileInfo info = profile.ProfileInfo;
                                        ProfileInfoDAL profileInfoDAL = new ProfileInfoDAL();
                                        int profileID = profileInfoDAL.InsertProfileInfo(profileCode, patientID, medicalID, infoSupplierID, info.Note, currentUser);
                                        if (profileID > 0)
                                        {
                                            ProfileStatusDAL statusDAL = new ProfileStatusDAL();
                                            int statusID = statusDAL.InsertProfileStatus(profileID, 2, 0, profile.InfoSupplierInfo.PersonalCode, null, null, null, "0", string.Empty, "text", null);
                                            if (statusID > 0)
                                            {
                                                new ProfileStageLinkDAL().InsertProfileStageLink(statusID, 1, string.Empty, string.Empty, string.Empty, DateTime.Now);
                                                result = true;

                                                System.Threading.Thread thread = new System.Threading.Thread(() => threadSendNotification(profileCode));
                                                thread.IsBackground = true;
                                                thread.Start();
                                            }
                                        }
                                    }
                                }
                            }
                            transScope.Complete();
                        }
                    }
                }
                catch (TransactionAbortedException transAbortEx)
                {
                }
                catch (Exception ex)
                {
                }

            }

            return result;
        }

        private void threadSendNotification(string profileCode)
        {
            DAL.NotificationDAL notificationDAL = new DAL.NotificationDAL();
            notificationDAL.sendNotification(@"Hồ Sơ " + profileCode + " vừa được đăng", 3);
        }

        public bool InsertProfileInfoWithMedia(Profile profile, string videoUrl, string photoUrl, string audioLink, string currentUser, DateTime createdDate, string description)
        {
            bool result = false;
            int patientID = 0;
            int medicalID = 0;
            int infoSupplierID = 0;
            if (profile != null)
            {
                try
                {
                    ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings["cnnString4T"];
                    if (ConnectionStringSettings != null && !string.IsNullOrEmpty(ConnectionStringSettings.ConnectionString.Trim()))
                    {
                        using (TransactionScope transScope = new TransactionScope())
                        {
                            using (SqlConnection connection = new SqlConnection(ConnectionStringSettings.ConnectionString))
                            {
                                string profileCode = string.Empty;
                                if (profile.ProfileInfo != null && string.IsNullOrEmpty(profile.ProfileInfo.ProfileInfoCode))
                                {
                                    ProfileDAL profileDAL = new ProfileDAL();
                                    profileCode = profileDAL.InsertNewProfile(null);
                                }
                                else
                                {
                                    profileCode = profile.ProfileInfo.ProfileInfoCode;
                                }

                                if (!string.IsNullOrEmpty(profileCode))
                                {
                                    if (profile.PatientInfo != null)
                                    {
                                        PatientInfo patient = profile.PatientInfo;
                                        PatientInfoDAL patientDAL = new PatientInfoDAL();
                                        patientID = patientDAL.InsertPatientInfo(patient.PatientName, patient.Birthday, patient.Gender, patient.IDNumber, patient.PermanentAddress, patient.TemporaryAddress, patient.MobileNumber, patient.PhoneNumber, patient.EmergencyRepresentative, patient.RepresentativePhoneNumber, patient.LocalContactPoint, patient.LocalContactPointPhoneNumber, patient.LocalMedicalStaff, patient.LocalMedicalStaffPhoneNumber, patient.MedicalFacility, patient.Note);
                                    }
                                    if (profile.MedicalInfo != null)
                                    {
                                        MedicalInfo medical = profile.MedicalInfo;
                                        MedicalInfoDAL medicalDAL = new MedicalInfoDAL();
                                        medicalID = medicalDAL.InsertMedicalInfo(medical.Diagnosis, medical.MedicalTime, medical.TreatmentMethod, medical.Situation, medical.Support, medical.Note);
                                    }
                                    if (profile.InfoSupplierInfo != null)
                                    {
                                        InfoSupplierInfo supplier = profile.InfoSupplierInfo;
                                        InfoSupplierInfoDAL supplierDAL = new InfoSupplierInfoDAL();
                                        infoSupplierID = supplierDAL.InsertInfoSupplierInfoFromCMS(supplier.SupplierName, supplier.PhoneNumber, profile.InfoSupplierInfo.PersonalCode, supplier.Email, supplier.Note);
                                    }

                                    if (patientID > 0 && medicalID > 0 && infoSupplierID > 0 && profile.ProfileInfo != null)
                                    {
                                        ProfileInfo info = profile.ProfileInfo;
                                        ProfileInfoDAL profileInfoDAL = new ProfileInfoDAL();
                                        int profileID = profileInfoDAL.InsertProfileInfo(profileCode, patientID, medicalID, infoSupplierID, info.Note, currentUser, createdDate);
                                        if (profileID > 0)
                                        {
                                            ProfileStatusDAL statusDAL = new ProfileStatusDAL();
                                            int statusID = statusDAL.InsertProfileStatus(profileID, 2, 0, currentUser, null, null, null, "0", string.Empty, "text", null);
                                            if (statusID > 0)
                                            {
                                                new ProfileStageLinkDAL().InsertProfileStageLink(statusID, 1, videoUrl, audioLink, photoUrl, createdDate);
                                                result = true;

                                                System.Threading.Thread thread = new System.Threading.Thread(() => threadSendNotification(profileCode));
                                                thread.IsBackground = true;
                                                thread.Start();
                                            }
                                        }
                                    }
                                }
                            }
                            transScope.Complete();
                        }
                    }
                }
                catch (TransactionAbortedException transAbortEx)
                {
                }
                catch (Exception ex)
                {
                }

            }

            return result;
        }

        public bool UpdateProfileInfoWithMedia(Profile profile, ProfileStageLink stageLink, string proposer, string currentUser, DateTime? editTime = null, string description = null)
        {
            bool result = false;
            int patientID = 0;
            int medicalID = 0;
            int infoSupplierID = 0;
            if (profile != null)
            {
                try
                {
                    ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings["cnnString4T"];
                    if (ConnectionStringSettings != null && !string.IsNullOrEmpty(ConnectionStringSettings.ConnectionString.Trim()))
                    {
                        using (TransactionScope transScope = new TransactionScope())
                        {
                            using (SqlConnection connection = new SqlConnection(ConnectionStringSettings.ConnectionString))
                            {
                                string profileCode = string.Empty;
                                if (profile.ProfileInfo != null && string.IsNullOrEmpty(profile.ProfileInfo.ProfileInfoCode))
                                {
                                    ProfileDAL profileDAL = new ProfileDAL();
                                    profileCode = profileDAL.InsertNewProfile(null);
                                }
                                else
                                {
                                    profileCode = profile.ProfileInfo.ProfileInfoCode;
                                }

                                if (!string.IsNullOrEmpty(profileCode))
                                {
                                    if (profile.PatientInfo != null)
                                    {
                                        PatientInfo patient = profile.PatientInfo;
                                        PatientInfoDAL patientDAL = new PatientInfoDAL();
                                        patientID = patientDAL.InsertPatientInfo(patient.PatientName, patient.Birthday, patient.Gender, patient.IDNumber, patient.PermanentAddress, patient.TemporaryAddress, patient.MobileNumber, patient.PhoneNumber, patient.EmergencyRepresentative, patient.RepresentativePhoneNumber, patient.LocalContactPoint, patient.LocalContactPointPhoneNumber, patient.LocalMedicalStaff, patient.LocalMedicalStaffPhoneNumber, patient.MedicalFacility, patient.Note);
                                    }
                                    if (profile.MedicalInfo != null)
                                    {
                                        MedicalInfo medical = profile.MedicalInfo;
                                        MedicalInfoDAL medicalDAL = new MedicalInfoDAL();
                                        medicalID = medicalDAL.InsertMedicalInfo(medical.Diagnosis, medical.MedicalTime, medical.TreatmentMethod, medical.Situation, medical.Support, medical.Note);
                                    }
                                    if (profile.InfoSupplierInfo != null)
                                    {
                                        InfoSupplierInfo supplier = profile.InfoSupplierInfo;
                                        InfoSupplierInfoDAL supplierDAL = new InfoSupplierInfoDAL();
                                        infoSupplierID = supplierDAL.InsertInfoSupplierInfoFromCMS(supplier.SupplierName, supplier.PhoneNumber, supplier.PersonalCode, supplier.Email, supplier.Note);
                                    }

                                    if (patientID > 0 && medicalID > 0 && infoSupplierID > 0 && profile.ProfileInfo != null)
                                    {
                                        ProfileInfo info = profile.ProfileInfo;
                                        ProfileInfoDAL profileInfoDAL = new ProfileInfoDAL();
                                        int profileID = profileInfoDAL.InsertProfileInfo(profileCode, patientID, medicalID, infoSupplierID, info.Note, currentUser, editTime);
                                        if (profileID > 0)
                                        {
                                            ProfileStatusDAL statusDAL = new ProfileStatusDAL();
                                            int statusID = statusDAL.InsertProfileStatus(profileID, 2, 0, proposer, null, null, null, "0", string.Empty, "text", null);
                                            if (statusID > 0)
                                            {
                                                if (stageLink != null)
                                                {
                                                    string rootUrl = ConfigurationManager.AppSettings["rootUrl"];
                                                    string video = stageLink.VideoLink;
                                                    if (video.Contains(rootUrl)) video = video.Substring(rootUrl.Length);
                                                    string audio = stageLink.AudioLink;
                                                    if (audio.Contains(rootUrl)) audio = video.Substring(rootUrl.Length);
                                                    string photo = stageLink.PhotoLink;
                                                    if (photo.Contains(rootUrl)) photo = video.Substring(rootUrl.Length);

                                                    new ProfileStageLinkDAL().InsertProfileStageLink(statusID, 1, video, audio, photo, editTime);
                                                }
                                                else
                                                {
                                                    new ProfileStageLinkDAL().InsertProfileStageLink(statusID, 1, null, null, null, editTime);
                                                }
                                                result = true;
                                            }
                                        }
                                    }
                                }
                            }
                            transScope.Complete();
                        }
                    }
                }
                catch (TransactionAbortedException transAbortEx)
                {
                }
                catch (Exception ex)
                {
                }

            }

            return result;
        }

        public string InsertProfileInfoWithErrorCode(Profile profile, string videoUrl, string photoUrl, string audioLink, string currentUser, DateTime createdDate, string description)
        {
            string result = string.Empty;
            int patientID = 0;
            int medicalID = 0;
            int infoSupplierID = 0;
            if (profile != null)
            {
                try
                {
                    ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings["cnnString4T"];
                    if (ConnectionStringSettings != null && !string.IsNullOrEmpty(ConnectionStringSettings.ConnectionString.Trim()))
                    {
                        using (TransactionScope transScope = new TransactionScope())
                        {
                            using (SqlConnection connection = new SqlConnection(ConnectionStringSettings.ConnectionString))
                            {
                                string profileCode = string.Empty;
                                if (profile.ProfileInfo != null && string.IsNullOrEmpty(profile.ProfileInfo.ProfileInfoCode))
                                {
                                    ProfileDAL profileDAL = new ProfileDAL();
                                    profileCode = profileDAL.InsertNewProfile(null);
                                }
                                else
                                {
                                    profileCode = profile.ProfileInfo.ProfileInfoCode;
                                }

                                if (!string.IsNullOrEmpty(profileCode))
                                {
                                    if (profile.PatientInfo != null)
                                    {
                                        PatientInfo patient = profile.PatientInfo;
                                        PatientInfoDAL patientDAL = new PatientInfoDAL();
                                        patientID = patientDAL.InsertPatientInfo(patient.PatientName, patient.Birthday, patient.Gender, patient.IDNumber, patient.PermanentAddress, patient.TemporaryAddress, patient.MobileNumber, patient.PhoneNumber, patient.EmergencyRepresentative, patient.RepresentativePhoneNumber, patient.LocalContactPoint, patient.LocalContactPointPhoneNumber, patient.LocalMedicalStaff, patient.LocalMedicalStaffPhoneNumber, patient.MedicalFacility, patient.Note);
                                    }
                                    if (profile.MedicalInfo != null)
                                    {
                                        MedicalInfo medical = profile.MedicalInfo;
                                        MedicalInfoDAL medicalDAL = new MedicalInfoDAL();
                                        medicalID = medicalDAL.InsertMedicalInfo(medical.Diagnosis, medical.MedicalTime, medical.TreatmentMethod, medical.Situation, medical.Support, medical.Note);
                                    }
                                    if (profile.InfoSupplierInfo != null)
                                    {
                                        InfoSupplierInfo supplier = profile.InfoSupplierInfo;
                                        InfoSupplierInfoDAL supplierDAL = new InfoSupplierInfoDAL();
                                        infoSupplierID = supplierDAL.InsertInfoSupplierInfoFromCMS(supplier.SupplierName, supplier.PhoneNumber, profile.InfoSupplierInfo.PersonalCode, supplier.Email, supplier.Note);
                                    }

                                    if (patientID > 0 && medicalID > 0 && infoSupplierID > 0 && profile.ProfileInfo != null)
                                    {
                                        ProfileInfo info = profile.ProfileInfo;
                                        ProfileInfoDAL profileInfoDAL = new ProfileInfoDAL();
                                        int profileID = profileInfoDAL.InsertProfileInfo(profileCode, patientID, medicalID, infoSupplierID, info.Note, currentUser, createdDate);
                                        if (profileID > 0)
                                        {
                                            ProfileStatusDAL statusDAL = new ProfileStatusDAL();
                                            int statusID = statusDAL.InsertProfileStatus(profileID, 2, 0, currentUser, null, null, null, "0", string.Empty, "text", null);
                                            if (statusID > 0)
                                            {
                                                new ProfileStageLinkDAL().InsertProfileStageLink(statusID, 1, videoUrl, audioLink, photoUrl, createdDate);
                                                result = "success";
                                            }
                                        }
                                    }
                                }
                            }
                            transScope.Complete();
                        }
                    }
                }
                catch (TransactionAbortedException transAbortEx)
                {
                    result = transAbortEx.Message;
                }
                catch (Exception ex)
                {
                    result = ex.Message;
                }

            }
            else
                result = "Profile cannot be null.";

            return result;
        }


        public List<ProfileStatus> GetListProfileWithPaging(int page, int pageSize, string searchText, int status)
        {
            ProfileInfoDAL profileInfoDAL = new ProfileInfoDAL();
            return profileInfoDAL.GetListProfileWithPaging(page, pageSize, searchText, status);
        }

        public void InsertProfileForVideoUpload(string uploader, string proposer, string videoUrl)
        {
            /*ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings["cnnString4T"];
            if (ConnectionStringSettings != null && !string.IsNullOrEmpty(ConnectionStringSettings.ConnectionString.Trim()))
            {
                ProfileDAL profileDAL = new ProfileDAL();
                string profileCode = profileDAL.InsertNewProfile(null);
                ProfileInfoDAL profileInfoDAL = new ProfileInfoDAL();
                int profileID = profileInfoDAL.InsertProfileInfoForVideo(profileCode, null);
                if (profileID > 0)
                {
                    ProfileStatusDAL statusDAL = new ProfileStatusDAL();
                    int statusID = statusDAL.InsertProfileStatus(profileID, 2, 0, proposer, null, null, null, "0", string.Empty, "video", uploader);
                    if (statusID > 0)
                    {
                        ProfileStageLinkDAL stageDAL = new ProfileStageLinkDAL();
                        stageDAL.InsertProfileStageLink(statusID, 1, videoUrl, null, null, null);
                    }
                }
            }*/
            PatientInfo patient = new PatientInfo(string.Empty, Convert.ToDateTime(DateTime.Now),
                string.Empty, string.Empty, string.Empty, string.Empty,
                string.Empty, string.Empty, string.Empty,
                string.Empty, string.Empty, string.Empty,
                string.Empty, string.Empty, string.Empty,
                string.Empty);
            MedicalInfo medical = new MedicalInfo(string.Empty, Convert.ToDateTime(DateTime.Now),
                string.Empty, string.Empty, string.Empty, string.Empty);
            string supplierCode = proposer;
            InfoSupplierInfo supplier = new InfoSupplierInfo(string.Empty,
                string.Empty, supplierCode, string.Empty, string.Empty);
            DateTime createdDate = Convert.ToDateTime(DateTime.Now);

            ProfileInfo profileInfo = new ProfileInfo();
            Profile profile = new Profile();
            profile.ProfileInfo = profileInfo;
            profile.PatientInfo = patient;
            profile.MedicalInfo = medical;
            profile.InfoSupplierInfo = supplier;
            ProfileBLL profileBLL = new ProfileBLL();
            bool result = profileBLL.InsertProfileInfoWithMedia(profile, videoUrl, string.Empty, string.Empty, supplierCode, createdDate, string.Empty);
        }

        public void InsertProfileForAudioUpload(string uploader, string proposer, string audioUrl)
        {
            /*ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings["cnnString4T"];
            if (ConnectionStringSettings != null && !string.IsNullOrEmpty(ConnectionStringSettings.ConnectionString.Trim()))
            {
                ProfileDAL profileDAL = new ProfileDAL();
                string profileCode = profileDAL.InsertNewProfile(null);
                ProfileInfoDAL profileInfoDAL = new ProfileInfoDAL();
                int profileID = profileInfoDAL.InsertProfileInfoForVideo(profileCode, null);
                if (profileID > 0)
                {
                    ProfileStatusDAL statusDAL = new ProfileStatusDAL();
                    int statusID = statusDAL.InsertProfileStatus(profileID, 2, 0, proposer, null, null, null, "0", string.Empty, "video", uploader);
                    if (statusID > 0)
                    {
                        ProfileStageLinkDAL stageDAL = new ProfileStageLinkDAL();
                        stageDAL.InsertProfileStageLink(statusID, 1, videoUrl, null, null, null);
                    }
                }
            }*/
            PatientInfo patient = new PatientInfo(string.Empty, Convert.ToDateTime(DateTime.Now),
                string.Empty, string.Empty, string.Empty, string.Empty,
                string.Empty, string.Empty, string.Empty,
                string.Empty, string.Empty, string.Empty,
                string.Empty, string.Empty, string.Empty,
                string.Empty);
            MedicalInfo medical = new MedicalInfo(string.Empty, Convert.ToDateTime(DateTime.Now),
                string.Empty, string.Empty, string.Empty, string.Empty);
            string supplierCode = proposer;
            InfoSupplierInfo supplier = new InfoSupplierInfo(string.Empty,
                string.Empty, supplierCode, string.Empty, string.Empty);
            DateTime createdDate = Convert.ToDateTime(DateTime.Now);

            ProfileInfo profileInfo = new ProfileInfo();
            Profile profile = new Profile();
            profile.ProfileInfo = profileInfo;
            profile.PatientInfo = patient;
            profile.MedicalInfo = medical;
            profile.InfoSupplierInfo = supplier;
            ProfileBLL profileBLL = new ProfileBLL();
            bool result = profileBLL.InsertProfileInfoWithMedia(profile, String.Empty, string.Empty, audioUrl, supplierCode, createdDate, string.Empty);
        }

        public List<ProfileInfoStatusDetail> GetAllProfile()
        {
            ProfileInfoDAL profileInfoDAL = new ProfileInfoDAL();
            List<ProfileStatus> statusList = profileInfoDAL.GetAllProfile();
            if (statusList != null && statusList.Count > 0)
            {
                List<ProfileInfoStatusDetail> result = new List<ProfileInfoStatusDetail>();
                ProfileStageLinkDAL stageDAL = new ProfileStageLinkDAL();
                for (int i = 0; i < statusList.Count; i++)
                {
                    ProfileStatus tmp = statusList[i];
                    ProfileInfoStatusDetail item = new ProfileInfoStatusDetail(tmp.ProfileCode, tmp.Stage,
                                                        tmp.Status, tmp.Proposer, tmp.Filter, tmp.Verifier,
                                                        tmp.Approver, tmp.Money, tmp.Note, tmp.PatientName, tmp.PaymentPerson, new List<ProfileStageLink>());
                    item.ListUrl = stageDAL.GetListProfileStatusLink(statusList[i].ProfileCode);
                    result.Add(item);
                }
                return result;
            }
            else
            {
                return null;
            }
        }

        public List<ProfileInfoStatusDetail> GetListProfilePaging(int page, int pageSize, string searchText, int status)
        {
            ProfileInfoDAL profileInfoDAL = new ProfileInfoDAL();
            List<ProfileStatus> statusList = profileInfoDAL.GetListProfileWithPaging(page, pageSize, searchText, status);

            if (statusList != null && statusList.Count > 0)
            {
                List<ProfileInfoStatusDetail> result = new List<ProfileInfoStatusDetail>();
                ProfileStageLinkDAL stageDAL = new ProfileStageLinkDAL();
                for (int i = 0; i < statusList.Count; i++)
                {
                    ProfileStatus tmp = statusList[i];
                    ProfileInfoStatusDetail item = new ProfileInfoStatusDetail(tmp.ProfileCode, tmp.Stage,
                                                        tmp.Status, tmp.Proposer, tmp.Filter, tmp.Verifier,
                                                        tmp.Approver, tmp.Money, tmp.Note, tmp.PatientName, tmp.PaymentPerson, new List<ProfileStageLink>());
                    item.ListUrl = stageDAL.GetListProfileStatusLink(statusList[i].ProfileCode);
                    result.Add(item);
                }
                return result;
            }
            else
            {
                return null;
            }
        }

        public List<CMS_SearchResult> SimpleSearch(string searchText)
        {
            ProfileInfoDAL profileInfoDAL = new ProfileInfoDAL();
            List<ProfileStatus> statusList = profileInfoDAL.SimpleSearch(searchText);

            if (statusList != null && statusList.Count > 0)
            {
                List<CMS_SearchResult> result = new List<CMS_SearchResult>();
                ProfileStageLinkDAL stageDAL = new ProfileStageLinkDAL();
                for (int i = 0; i < statusList.Count; i++)
                {
                    ProfileStatus tmp = statusList[i];
                    CMS_SearchResult item = new CMS_SearchResult { Code = tmp.ProfileCode, Name = tmp.PatientName };
                    result.Add(item);
                }
                return result;
            }
            else
            {
                return null;
            }
        }

        public List<ProfileInfoAndStatus> GetListProfileInfoAndStatus(int page, int pageSize, string searchText, int status)
        {
            ProfileInfoDAL profileInfoDAL = new ProfileInfoDAL();
            return profileInfoDAL.GetListProfileInfoAndStatus(page, pageSize, searchText, status);
        }

        public List<CMS_Profile> GetProfileListForCMS(int page, int pageSize, string searchText)
        {
            ProfileDAL profileDAL = new ProfileDAL();
            return profileDAL.GetProfileList(page, pageSize, searchText);
        }

        public List<CMS_Profile> GetProfileListForCMS()
        {
            ProfileDAL profileDAL = new ProfileDAL();
            return profileDAL.GetProfileList();
        }

        public int GetProfileTotalRecordForCMS()
        {
            ProfileDAL profileDAL = new ProfileDAL();
            return profileDAL.GetProfileTotalRecordForCMS();
        }

        public CMS_Profile GetProfileByProfileCode(string profileCode)
        {
            ProfileDAL profileDAL = new ProfileDAL();
            return profileDAL.GetProfileByProfileCode(profileCode);
        }

        public List<CMS_ProfileFilter> GetProfileFilterList(int page, int pageSize, string searchText)
        {
            return new ProfileInfoDAL().GetListProfileFilter(page, pageSize, searchText);
        }

        public CMS_VideoUploadInfo GetVideoUploadInfo(string profileInfoCode)
        {
            return new ProfileDAL().GetVideoUploadInfo(profileInfoCode);
        }
    }
}